
#include "Components/algorithm.h"
#include "Components/basic.h"
#include "Components/line_patrol.h"
#include "Components/motion.h"
#include "Components/motor.h"
#include "Components/oled_hardware_i2c.h"
#include "Components/servo.h"
#include "Components/ATK_MS901M/atk_ms901m.h"
#include "Components/simple_json.h"
#include <ti/driverlib/m0p/dl_interrupt.h>

#define TAG "Main"

atk_ms901m_attitude_data_t attitude_dat;           /* ��̬������ */
atk_ms901m_gyro_data_t gyro_dat;                   /* ���������� */
atk_ms901m_accelerometer_data_t accelerometer_dat; /* ���ٶȼ����� */
atk_ms901m_magnetometer_data_t magnetometer_dat;   /* ���������� */
atk_ms901m_barometer_data_t barometer_dat;         /* ��ѹ������ */

void demo_key0_fun(void)
{
  atk_ms901m_get_attitude(&attitude_dat, 1); /* ��ȡ��̬������ */
                                             // atk_ms901m_get_gyro_accelerometer(&gyro_dat, &accelerometer_dat, 1); /* ��ȡ�����ǡ����ٶȼ����� */
                                             // atk_ms901m_get_magnetometer(&magnetometer_dat, 1);                   /* ��ȡ���������� */
                                             // atk_ms901m_get_barometer(&barometer_dat, 1);                         /* ��ȡ��ѹ������ */

  my_printf("Roll: %.02f Pitch: %.02f Yaw: %.02f\r\n", attitude_dat.roll, attitude_dat.pitch, attitude_dat.yaw);
  // my_printf("Gx: %.02f/s Gy: %.02f/s Gz: %.02f/s\r\n", gyro_dat.x, gyro_dat.y, gyro_dat.z);
  // my_printf("Ax: %.02fG Ay: %.02fG Az: %.02fG\r\n", accelerometer_dat.x, accelerometer_dat.y, accelerometer_dat.z);
  // my_printf("Mx: %d My: %d Mz: %d, Temp: %.02f\r\n", magnetometer_dat.x, magnetometer_dat.y, magnetometer_dat.z, magnetometer_dat.temperature);
  // my_printf("Pres: %dPa Alt: %dcm Temp: %.02f\r\n", barometer_dat.pressure, barometer_dat.altitude, barometer_dat.temperature);
  // my_printf("****************************************\r\n\r\n");
}

int main(void)
{
  SYSCFG_DL_init();
  SysTick_Init();
  uart_init();
  OLED_Init();

  OLED_ShowString(0, 0, "Attitude Test", 16);

  if (atk_ms901m_init(115200) != 0)
  {
    log(TAG, "ATK-MS901M Init Failed!");
    OLED_ShowString(0, 2, "Failed", 16);
    while (1)
      ;
  }

  log(TAG, "Attitude Test Init Done!");

  while (1)
  {
    demo_key0_fun();
    // mspm0_delay_ms(1);
  }
}
